<?php

namespace App\Http\Controllers\Api;

use App\Events\addLog;
use App\Http\Controllers\Controller;
use App\Http\Resources\PrintResource;
use App\Models\Student;
use Illuminate\Support\Facades\Auth;

class PrintController extends Controller
{

    public function allStudent($id)
    {
        $model = Student::query()->where('id',$id)->first();
        $entity_id = $model->entity_id;
        $model = Student::query()->where('entity_id',$entity_id)->get();
        return PrintResource::collection($model);
    }

    /**
     * @param $id
     * @return \Illuminate\Database\Eloquent\Model|null|object|static
     */
    public function findModel($id){
        $model = Student::query()->where('id',$id)->first();
        return $model;
    }

    public function printInfo($id)
    {
        $student_name = Student::query()->where('id',$id)->first()->name;
        event(new addLog(Auth::user(),'打印'.$student_name.'的报名信息'));
    }
}
